package com.situ.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.situ.mall.pojo.entity.Product;
import com.situ.mall.mapper.ProductMapper;
import com.situ.mall.pojo.query.ProductQuery;
import com.situ.mall.pojo.vo.ProductVO;
import com.situ.mall.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Gao
 * @since 2025-09-10
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public IPage<ProductVO> list(ProductQuery productQuery) {
        IPage<ProductVO> page  = new Page<>(productQuery.getPage(), productQuery.getLimit());
        return productMapper.list(page, productQuery);
    }

    @Override
    public Set<String> selectAllImage() {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("main_image");
        queryWrapper.isNotNull("main_image");
        List<Product> list = productMapper.selectList(queryWrapper);
        Set<String> set = new HashSet<>();
        for (Product product : list) {
            set.add(product.getMainImage());
        }
        return set;
    }

    @Override
    public List<Product> selectByCategoryId(Integer categoryId) {
        return productMapper.selectByCategoryId(categoryId);
    }
}
